package unq.tpi.persistencia.alumnos.arq.runner;

import unq.tpi.persistencia.alumnos.arq.Service;

public class LogRunner extends RunnerDecorator {

	public LogRunner(Runner inner) {
		super(inner);
	}

	public <T> T run(Service<T> service) {
		T result;
		long time;
		
		log.info("Inicio: " + service.getClass());
		time = System.currentTimeMillis();
		
		try{
			result = super.run(service);
			time = System.currentTimeMillis() - time;
			
			log.info("Fin: " + service.getClass() + " Tiempo:" + time + "ms");
			return result;
		}catch(RuntimeException e){
			time = System.currentTimeMillis() - time;
			log.error("Fin: " + service.getClass() + " Tiempo:" + time + "ms",e);
			throw e;
		}
	}

}
